//
//  MyTabbarController.swift
//  SWfanghu
//
//  Created by 李言 on 16/6/6.
//  Copyright © 2016年 ly. All rights reserved.
//

import UIKit

class MyViewController: BaseviewController {
//MARK: property
    var topview:UIView!
    var touxiang:UIImageView!
    var name:UILabel!
    var city:UILabel!
    var invant:UILabel!
    var phoneNum:UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()

        // 这个是必要的设置
        automaticallyAdjustsScrollViewInsets = false

        navigationController?.navigationBar.hidden = false

        var style = SegmentStyle()
        // 滚动条
        style.showLine = true
        // 滚动条颜色
        style.scrollLineColor = color_import_red
        let titles = setChildVcs().map { $0.title! }

        // topView
        addTopview()

        let scroll = ScrollPageView(frame: CGRect(x: 0, y: topview.frame.maxY, width: view.bounds.size.width, height: view.bounds.size.height - topview.frame.maxY - (tabBarController?.tabBar.frame.height)!), segmentStyle: style, titles: titles, childVcs: setChildVcs(), parentViewController: self)
        view.addSubview(scroll)
        
        // FIXME: 临时弹出看效果
        let nav = UINavigationController(rootViewController: LoginController())
        presentViewController(nav, animated: true, completion: nil)
    }
    func addTopview(){
        topview = UIView(frame: CADipRectMake(0, self.navbarHeight, self.frameSize.width, 280))
        topview.backgroundColor = color_import_red
        
        let fonNum:CGFloat = 14
        
        var y:CGFloat = (280-120)/2
        
        touxiang = UIImageView(image: UIImage(named:"touxiang"))
        touxiang.frame = CADipRectMake(spaceHeight, y, 120, 120)
        topview.addSubview(touxiang)
        
        var x = spaceHeight*2+120
        
        name = UILabel(CADipX: x, CADipY: y, string: "我的名字")
        name.textColor = UIColor.whiteColor()
        topview.addSubview(name)
        
        y += name.getLabelCADipSize().height + spaceHeight

        var lab = UILabel(CADipX: x, CADipY: y, string: "城市:", font: fonNum)
        lab.textColor = UIColor.whiteColor()
        topview.addSubview(lab)
        
        x += lab.getLabelCADipSize().width + 10
        
        city = UILabel(CADipX: x, CADipY: y, string: "北京", font: fonNum)
        city.textColor = UIColor.whiteColor()
        topview.addSubview(city)
        
        x += city.getLabelCADipSize().width + spaceHeight
        
        lab = UILabel(CADipX: x, CADipY: y, string: "邀请码:", font: fonNum)
        lab.textColor = UIColor.whiteColor()
        topview.addSubview(lab)
        
        x += lab.getLabelCADipSize().width + 10
        
        invant = UILabel(CADipX: x, CADipY: y, string: "123456", font: fonNum)
        invant.textColor = UIColor.whiteColor()
        topview.addSubview(invant)
        
        x = spaceHeight*2+120
        y += invant.getLabelCADipSize().height + spaceHeight
        
        lab = UILabel(CADipX: x, CADipY: y, string: "手机号:", font: fonNum)
        lab.textColor = UIColor.whiteColor()
        topview.addSubview(lab)
        
        x += lab.getLabelCADipSize().width + 10
        
        phoneNum = UILabel(CADipX: x, CADipY: y, string: "138282828", font: fonNum)
        phoneNum.textColor = UIColor.whiteColor()
        topview.addSubview(phoneNum)
        
        
        view.addSubview(topview)

    }
    func setChildVcs() -> [UITableViewController] {

        let vc1 = MyOrderListController()
        vc1.title = "所有订单"

        let vc2 = MyAlreadyCommentController()
        vc2.title = "已评房"

        let vc3 = MyAlreadyFailureTableViewController()
        vc3.title = "已失败"
        
        return [vc1, vc2, vc3]
    }
}
